import pymysql

conn = pymysql.connect(user='root', password='root', database='assistant', charset='utf8',port=3306,host="localhost",cursorclass=pymysql.cursors.DictCursor)

def query_user_no_exits(username):
    sql = "select * from sys_user where username = %s"
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    if result is None:
        return True
    else:
        return False

def add_user(username, password):
    sql = "insert into sys_user (username, password) values (%s, %s)"
    cur = conn.cursor()
    cur.execute(sql, [username, password])
    conn.commit()

def query_user(username):
    sql = "select username from sys_user where username = %s"
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    if result is not None:
        return True
    else:
        return False

def query_user_password(username):
    sql = "select username,password from sys_user where username = %s"
    cur = conn.cursor()
    cur.execute(sql, [username])
    result = cur.fetchone()
    return result